package aom.ju.ss.view.base

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import aom.ju.ss.R


class ImgProgressBar(con: Context, attrs: AttributeSet) : FrameLayout(con, attrs) {
    var w = 0
    var p: ImageView
    var hk: View
    var root: View

    init {
        LayoutInflater.from(context).inflate(R.layout.img_progress_bar, this)
        p = findViewById(R.id.p)
        hk = findViewById(R.id.hk)
        root = findViewById(R.id.root_view)

    }

    fun setProgress(progress: Int? = 0) {
        var progres = 0
        if (progress != null) {
            progres = progress
        }
        root.post {
            if (w == 0) {
                w = root.measuredWidth / 100
            }
            val fl = p.layoutParams as LayoutParams
            fl.width = root.measuredWidth - w * progres

            hk.post {
                hk.x = (w * progres).toFloat()
            }
            p.layoutParams = fl
        }
    }
}